<template>
  <j-modal
    :title="'设置亮度'"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
   <a-spin :spinning="confirmLoading">
    <j-form-container>
      <a-form-model ref="form" :model="model">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <span>{{model.name}}</span>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="亮度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bri">
              <a-col :span="18">
                      <a-slider v-model:value="model.bri" :min="0" :max="100" :step="1" />
                    </a-col>
                    <a-col :span="4">
                      <a-input-number
                        v-model:value="model.bri"
                        :min="0"
                        :max="100"
                        :step="1"
                        style="margin-left: 16px"
                      />
                    </a-col>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
  </j-modal>
</template>

<script> 
  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  export default{
    name:'brightnessModal',
    components:{ 
    },
    data(){
      return {
        visible:false,
        width:600,
        disableSubmit: false,
        model:{
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false
      }
    },
    methods:{
      handleCancel () {
        this.close()
      },
      show (record) { 
        this.model = Object.assign({}, record);
        if(!this.model.bri){
          this.model.bri = 0
        }
        this.visible = true;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = "/corp/lamp/control?id="+that.model.id+"&bri="+that.model.bri;
            httpAction(httpurl,{},"get").then((res)=>{
              if(res.success){
                that.$message.success("操作成功");
                that.visible = false;
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      }, 
      close () {
        this.visible = false;
      },
    }
  }
</script>

<style>
</style>